const viewerInit = function(){
    const viewer = new Cesium.Viewer('cesiumContainer', {
        baseLayerPicker: false,   //图层选择器
        animation: false,   //左下角仪表
        fullscreenButton: false,   //全屏按钮
        geocoder: false,   //右上角查询搜索
        infoBox: false,   //信息框
        homeButton: false,   //home按钮
        sceneModePicker: false,  //3d 2d选择器
        selectionIndicator: false,  //
        timeline: false,   //时间轴
        navigationHelpButton: false,  //右上角帮助按钮
        // requestRenderMode : true,
        // maximumRenderTimeChange : Infinity ,
        shouldAnimate : true,//允许动画 //这个得必须有！！
        skyBox: new Cesium.SkyBox({
			sources: {
				positiveX: 'data/images/skybox/px.jpg',
				negativeX: 'data/images/skybox/mx.jpg',
				positiveY: 'data/images/skybox/py.jpg',
				negativeY: 'data/images/skybox/my.jpg',
				positiveZ: 'data/images/skybox/pz.jpg',
				negativeZ: 'data/images/skybox/mz.jpg',
			},
		}),
        imageryProvider: new Cesium.TileMapServiceImageryProvider({
          url: Cesium.buildModuleUrl("Assets/Textures/NaturalEarthII"),
        }),
        contextOptions:{
            webgl:{
                //实现截图需要将该项设置为true
                preserveDrawingBuffer:true,
            },
        },
    })
    //浅拷贝

    window.viewer = viewer;
    // if (!viewer.graphicLayer) {
    //     viewer['graphicLayer'] = new GV.GraphicLayer(viewer);
    // }
    // window.graphicLayer = viewer.graphicLayer;
    // viewer.cesiumWidget.creditContainer.style.display="none";


    // viewer.scene.requestRenderMode = true;
    // viewer.scene.screenSpaceCameraController.enableRotate = false;
    // viewer.scene.screenSpaceCameraController.enableTilt = false;
    // viewer.scene.debugShowFramesPerSecond = true;
    // viewer.resolutionScale
    viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
    if(!window.isOnline){
        // Arc 影像
        // let Image=new Cesium.ArcGisMapServerImageryProvider({
        //     url : 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
        // });
        // let black = new Cesium.WebMapTileServiceImageryProvider({
        //     url: "http://221.1.66.166:8320/tilecache/service/wmts",
        //     layer: "Global_Vector_Map-JPEG-3857",
        //     style: "default",
        //     format: "image/jpeg",
        //     tileMatrixSetID: "EPSG:3857",
        //     //tilingScheme: new Cesium.GeographicTilingScheme()
        // })
        //http://172.25.110.35:8310/tilecache/service/wmts?layer=hainan_image-JPEG-4326&tilematrixset=EPSG%3A4326&Service=WMTS&Request=GetTile&Version=1.0.0&Format=image%2Fjpeg&TileMatrix=EPSG%3A4326%3A{7}&TileCol={y}&TileRow={x}
        let Image = new Cesium.WebMapTileServiceImageryProvider({
            url: "http://36.112.11.166:8310/tilecache/service/wmts",
            layer: "image_globle_base-JPEG-4326",
            format: "image/jpeg",
            style: "default",
            maximumLevel: 19,
            tileMatrixSetID: "EPSG:4326",
            tilingScheme: new Cesium.GeographicTilingScheme()
        })              
        let Label = new Cesium.WebMapTileServiceImageryProvider({
            url: "http://36.112.11.166:8310/tilecache/service/wmts",
            layer: "Global_ImageLabel17-PNG-4326",
            format: "image/png",
            style: "default",
            maximumLevel: 17,
            tileMatrixSetID: "EPSG:4326",
            tilingScheme: new Cesium.GeographicTilingScheme()
        })
        // let guge = new Cesium.UrlTemplateImageryProvider({
        //     url:"http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
        // })
        viewer.imageryLayers.addImageryProvider(Image)
        viewer.imageryLayers.addImageryProvider(Label)
        //viewer.imageryLayers.addImageryProvider(Label)
        // 地形
        window.dx = new Cesium.CesiumTerrainProvider({
            url:'https://www.supermapol.com/realspace/services/3D-stk_terrain/rest/realspace/datas/info/data/path',
            requestWaterMask:false ,
            requestVertexNormals: false
        })
        viewer.scene._terrainExaggeration = 1.5
        viewer.terrainProvider = window.dx
    }else{
        //影像
        viewer.imageryLayers.addImageryProvider(
            new Cesium.WebMapTileServiceImageryProvider({
                url: window.baseLayer.url,
                layer: window.baseLayer.layer,
                style: window.baseLayer.style,
                format: window.baseLayer.format,
                tileMatrixSetID: window.baseLayer.tileMatrixSetID,
                tilingScheme: new Cesium.GeographicTilingScheme()
            })
        )
        //viewer.imageryLayers.addImageryProvider(
            //红线管控
            // new Cesium.WebMapTileServiceImageryProvider({
            //     url: "http://59.212.226.90:6080/arcgis/rest/services/hainan/%E8%A7%84%E5%88%92%E7%AE%A1%E6%8E%A7%E7%B1%BB/MapServer/WMTS",
            //     layer: "hainan_规划管控类",
            //     style: "default",
            //     format: "image/png",
            //     tileMatrixSetID: "default028mm",
            //     tilingScheme: new Cesium.GeographicTilingScheme()
            // })
            // new Cesium.WebMapTileServiceImageryProvider({
            //     url: "http://59.212.146.170/ime-cloud/rest/hainan_vec/wmts",
            //     layer: "hainan_vec",
            //     style: "default",
            //     format: "image/png",
            //     tileMatrixSetID: "default028mm",
            //     tilingScheme: new Cesium.GeographicTilingScheme(),
            //     //tileMatrixLabels:['8','9','10','11','12','13','14','15','16','17','18','19']
            // })
        //)
        // let url = "http://59.212.146.170:80/ime-cloud/rest/hn_road/wmts";
        // let layer = "hn_road"
        // let curLayer = new Cesium.UrlTemplateImageryProvider({
        //     url: `${url}?layer=${layer}&style=default&tilematrixset=default028mm&Service=WMTS&Request=GetTile&Version=1.0.0&Format={format}&TileMatrix={TileMatrix}&TileRow={y}&TileCol={x}`,
        //     layer: layer ,
        //     style: "default",
        //     format: "image/png",
        //     tileMatrixSetID: "default028mm",
        //     tilingScheme: new Cesium.GeographicTilingScheme(),
        //     //动态计算level
        //     customTags:{
        //         TileMatrix:function(imageryProvider, x, y, level){
        //             return level+1;
        //         },
        //     },
        //     //图层拾取
        //     // pickFeaturesUrl: `${treeNode.publishInfo.wmsURL}?layers=0&query_layers=0&style=&crs=EPSG:4326&Service=WMS&Request=GetFeatureInfo&Version=1.3.0&info_format=text/html&i={i}&j={j}&width={width}&height={height}&bbox={southDegrees},{westDegrees},{northDegrees},{eastDegrees}`,
        //     // //图层拾取回调
        //     // getFeatureInfoFormats: [new Cesium.GetFeatureInfoFormat( "html","text/html", callback)]
        // })
        //viewer.imageryLayers.addImageryProvider(curLayer)
        //地名
        viewer.imageryLayers.addImageryProvider(
            new Cesium.WebMapTileServiceImageryProvider({
                url: window.labelLayer.url,
                layer: window.labelLayer.layer,
                style: window.labelLayer.style,
                format: window.labelLayer.format,
                tileMatrixSetID: window.labelLayer.tileMatrixSetID,
                tilingScheme: new Cesium.GeographicTilingScheme()
            })
        )
        //地形
        window.dx = new Cesium.CesiumTerrainProvider({
            url: window.terrainUrl,
            requestWaterMask:true,
            requestVertexNormals: true
        })
        viewer.terrainProvider = window.dx
        viewer.scene._terrainExaggeration = 1.5
    }
    
    //viewer.scene.globe.depthTestAgainstTerrain = false;

   
    //夜间模式
    // viewer.scene.globe.enableLighting = true//必须开启光照效果，
    // var layer = viewer.scene.imageryLayers.addImageryProvider(
    //     new Cesium.SingleTileImageryProvider({
    //         url: './data/images/earth/black.jpg'
    //     })
    // )
    // layer.dayAlpha = 0.0 //白天图层透明值
    // layer.nightAlpha = 1.0 //夜晚图层透明值
    // layer.brightness = 2.5 //图层发光亮度
    //
}
export default  viewerInit;